package com.lbs.jiepiaisi.view;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lbs.jiepiaisi.R;
import com.lbs.jiepiaisi.activity.VisitTypeActivity;
import com.lbs.jiepiaisi.activity.WorkHomeOrderAddActivity;
import com.lbs.jiepiaisi.utils.ButtonUtil;

import java.util.HashMap;

/**
 * @author ydm
 * @date 2018/2/20
 * @desc
 */

public class WorkOrderSingleView extends LinearLayout {

    private TextView mLeft;
    private TextView mCenter;
    private TextView mRight;
    private ImageView mImageView;

    private int position;

    private Context mContext;

    public WorkOrderSingleView(Context context) {
        super(context);
        initView(context);
    }

    public WorkOrderSingleView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public WorkOrderSingleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context){
        this.mContext = context;
        // 加载布局
        LayoutInflater.from(context).inflate(R.layout.view_order_single, this);
        // 获取控件

        mLeft =  (TextView)findViewById(R.id.tv_left);

        mRight = (TextView)findViewById(R.id.tv_right);

        mCenter = (TextView)findViewById(R.id.tv_center);

        mImageView = (ImageView)findViewById(R.id.iv_right);
    }

    public void setContent(final int position, final  String device, String num,HashMap<String,String> workEqnos){
        if(workEqnos.get(position+"") == null){
            if(num == null || num.length() < 2){
                mRight.setVisibility(GONE);
                mImageView.setVisibility(VISIBLE);
                mCenter.setText("x "+num);
            }else {
                mRight.setVisibility(VISIBLE);
                mImageView.setVisibility(GONE);
                mRight.setText("已拍完");
                mCenter.setText(num);
            }


            mImageView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(ButtonUtil.isFastClick()){
                        Intent intent = new Intent(mContext, VisitTypeActivity.class);
                        intent.putExtra("position",position);
                        intent.putExtra("eqModel",device);
                        mContext.startActivity(intent);
                    }
                }
            });


        }else {
            mRight.setVisibility(VISIBLE);
            mImageView.setVisibility(GONE);
            mRight.setText("已拍完");
            mCenter.setText(workEqnos.get(position+""));
        }
        mLeft.setText(device);




    }
    public void updateContent(String num){
        if(num == null || num.length() < 2){
            mRight.setVisibility(GONE);
            mImageView.setVisibility(VISIBLE);
            mCenter.setText("x "+num);
        }else {
            mRight.setVisibility(VISIBLE);
            mImageView.setVisibility(GONE);
            mRight.setText("已拍完");
            mCenter.setText(num);
        }
    }

}
